package com.zis.auction.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zis.auction.dao.AuctFocusDao;
import com.zis.auction.model.AuctUserFocus;
import com.zis.auction.service.IAuctUserFocusInter;
import com.zis.base.impl.BaseInterImpl;
import com.zis.core.Constant;
import com.zis.core.ResponseEntity;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Create by wangshen 2018/1/2
 */
@Service
@Transactional("txManager")
public class AuctUserFocusInterImpl extends BaseInterImpl<AuctUserFocus> implements IAuctUserFocusInter {


    @Autowired
    private SQLManager sqlManager;

    @Autowired
    private AuctFocusDao auctFocusDao;

    @Override
    public String insert(AuctUserFocus auctUserFocus) throws Exception {
        int num = sqlManager.insert(auctUserFocus);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public String update(AuctUserFocus auctUserFocus) throws Exception {
        return null;
    }

    @Override
    public String delete(String id) throws Exception {
        return null;
    }

    @Override
    public AuctUserFocus selectById(String id) throws Exception {
        return null;
    }

    @Override
    public List<AuctUserFocus> findByCondition(AuctUserFocus auctUserFocus) throws Exception {
        return sqlManager.template(auctUserFocus);
    }

    @Override
    public String findByAusId(String ausId, Integer page, Integer pageSize) throws Exception {
        List<AuctUserFocus> focusList = auctFocusDao.findByAusId(ausId, page ,pageSize);
        if(focusList!=null&&focusList.size()>0){
            JSONObject result = new JSONObject();
            result.put("data", focusList);
            result.put("page", page);
            result.put("pageSize", pageSize);
            return ResponseEntity.createNormalJsonResponse(result);
        }
        return ResponseEntity.createNULLJsonResponse("未查询到相关数据");
    }

    @Override
    public void deleteByBussAndAus(String bussId, String ausId) {
        auctFocusDao.deleteByBussAndAus(bussId, ausId);
    }
}
